package com.jiaai.handler;

import com.jiaai.exception.ServerException;
import com.jiaai.util.RestResult;
import com.jiaai.util.RestResultGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class RestExceptionHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(RestExceptionHandler.class);

    public RestExceptionHandler() {
    }

    @ExceptionHandler({ServerException.class})
    @ResponseBody
    private <T> RestResult<T> serverExceptionHandler(ServerException e) {
        LOGGER.error("服务器内部异常 ---[msg]:{}---[description]:{}", e.getMessage(), e.getLocalizedMessage());
        return RestResultGenerator.genErrorResult(500,e.getMessage());
    }




}
